package com.huc.event;

import com.huc.entity.Order;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @auther huc
 * @date 2020/8/24 0024 AM 9:46
 */
@Component
public class OrderListener {
    /**
     * @Order注解是控制执行顺序
     * @param orderEvent
     */
    @org.springframework.core.annotation.Order(2)
    @Async
    @EventListener
    public void sendMsg(OrderEvent orderEvent) {
        Order order=orderEvent.getOrder();
        System.out.println(order.toString());
        System.out.println(String.format("[%s]线程调用短信系统发送信息给[%s]",
                Thread.currentThread().getName(), order.getUsername()));

    }
    @org.springframework.core.annotation.Order(1)
    @Async
    @EventListener
    public void editGoodNum(OrderEvent orderEvent) {
        Order order=orderEvent.getOrder();
        System.out.println(order.toString());
        System.out.println(String.format("[%s]线程调用库存系统扣减【[%s]】商品库存",
                Thread.currentThread().getName(),order.getTitle()));

    }
}
